package FTPWrapper;

# $Id: FTPWrapper.pm 124 2010-06-26 14:42:13Z dolbanavt $
# $Date: 2010-06-26 17:42:18 +0300 (Суб, 26 Июн 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/lib/FTPWrapper.pm $
# $LastChangedRevision: 348 $

use parent qw( JIP::BaseClass Class::Accessor::Fast );
use JIP::ToolSet;
use Carp qw( croak );
use English qw( -no_match_vars );
use JIP::Utils qw( check_named_params );

our $VERSION = '1.0';

__PACKAGE__->follow_best_practice;

__PACKAGE__->mk_accessors( qw( connection listing_decorator ) );

sub _init {
    my ( $self, $params_ref ) = @ARG;

    check_named_params(
        rules_ref  => {
            connection => { required => 1, defined  => 1 },
            decorator  => { required => 1, defined  => 1 }
        },
        params_ref => $params_ref,
    );

    $self->set_connection( $params_ref->{'connection'} );
    $self->set_listing_decorator( $params_ref->{'decorator'} );

    return $self;
}

sub get_listing_for {
    my ( $self, $path ) = @ARG;

    return $self->get_listing_decorator->parse_listing_for(
        $self->get_connection->dir( $path )
    );
}

1;

__END__

=head1 NAME

FTPWrapper - обертка над стандартным Net::FTP

=head1 SYNOPSIS

    use FTPWrapper;

    my $w = FTPWrapper->new(
        connection => Net::FTP->new(),
        decorator  => FTPListing->new(),
    );

    my @listing_records = $w->get_listing_for('/path/to/dir');

    say $listing_records[0]->{'name'};
    say $listing_records[0]->{'type'};

=head1 DEPENDENCIES

Class::Accessor::Fast (from CPAN)

JIP::ToolSet (from base_lib)

JIP::BaseClass (from base_lib)

JIP::Utils (from base_lib)

=head1 AUTHOR

Vladimir Zhavoronkov, <dolbanavt (at) Google Mail>

http://dolbanavt.livejournal.com/

=head1 LICENSE AND COPYRIGHT

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

=cut
